package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CArrivalRecordDao;
import com.hongxun.modules.csg.entity.CArrivalRecordEntity;
import com.hongxun.modules.csg.service.CArrivalRecordService;



@Service("cArrivalRecordService")
public class CArrivalRecordServiceImpl implements CArrivalRecordService {
	@Autowired
	private CArrivalRecordDao cArrivalRecordDao;
	
	@Override
	public CArrivalRecordEntity queryObject(String guid){
		return cArrivalRecordDao.queryObject(guid);
	}
	
	@Override
	public List<CArrivalRecordEntity> queryList(Map<String, Object> map){
		return cArrivalRecordDao.queryList(map);
	}

	@Override
	public List<CArrivalRecordEntity> queryListToSPName(Map<String, Object> map){
		return cArrivalRecordDao.queryListToSPName(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cArrivalRecordDao.queryTotal(map);
	}
	
	@Override
	public void save(CArrivalRecordEntity cArrivalRecord){
        if(cArrivalRecord.getGuid()==null||cArrivalRecord.getGuid().equals("")) {

		    cArrivalRecord.setGuid(UUID.randomUUID().toString());
        }
		cArrivalRecordDao.save(cArrivalRecord);
	}
	
	@Override
	public void update(CArrivalRecordEntity cArrivalRecord){
		cArrivalRecordDao.update(cArrivalRecord);
	}
	
	@Override
	public void delete(String guid){
		cArrivalRecordDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cArrivalRecordDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CArrivalRecordEntity> entities) {
		for (CArrivalRecordEntity d : entities) {
			if (d.getARDatastate().equals("删除")) {
				cArrivalRecordDao.delete(d.getGuid());
			} else {
				CArrivalRecordEntity cArrivalRecordEntity = cArrivalRecordDao.queryObject(d.getGuid());
				if (cArrivalRecordEntity == null) {
					cArrivalRecordDao.save(d);
				} else {
					cArrivalRecordDao.update(d);
				}
			}
		}
	}
	
}
